package cn.com.jinhao.provider.business.controller;

import cn.com.jinhao.hotline.commons.controller.BaseController;
import cn.com.jinhao.hotline.commons.util.RestResponse;
import cn.com.jinhao.provider.business.entity.WorkTerminalCache;
import cn.com.jinhao.provider.business.service.WorkTerminalCacheService;
import io.swagger.annotations.*;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * hotline-spring-cloud
 * <p>Description: </p>
 *
 * @author ShaneMew
 * @version 1.0
 * @date 2020/6/8
 * @since 2020/6/8
 */
@RestController
@RequestMapping("/workTerminalCache")
@Api(tags = "接线工作台服务")
public class WorkTerminalCacheController extends BaseController {
    @Resource
    WorkTerminalCacheService workTerminalCacheService;

    @ApiOperation(value = "新增接线工作台缓存")
    @PostMapping
    public RestResponse<String> add(@ApiParam(name = "workTerminalCache", value = "接线工作台信息") @Validated @RequestBody WorkTerminalCache workTerminalCache, BindingResult result) throws Exception {
        validate(result);
        workTerminalCacheService.add(workTerminalCache);
        return new RestResponse<>("true");
    }

    @ApiOperation(value = "更新接线工作台缓存")
    @PutMapping
    public RestResponse<String> update(@ApiParam(name = "workTerminalCache", value = "接线工作台信息") @Validated @RequestBody WorkTerminalCache workTerminalCache, BindingResult result) throws Exception {
        validate(result);
        workTerminalCacheService.update(workTerminalCache);
        return new RestResponse<>("true");
    }

    @ApiOperation(value = "删除接线工作台缓存")
    @DeleteMapping
    public RestResponse<String> delete(@ApiParam(name = "callId", value = "话务ID") @RequestParam String callId) throws Exception {
        workTerminalCacheService.delete(callId);
        return new RestResponse<>("true");
    }

    @ApiOperation(value = "查询接线工作台", notes = "通过用户编码和部门编码查询出当前用户的所有工作太列表")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "operCode",  value= "用户编码", required = true),
        @ApiImplicitParam(name = "deptCode",  value= "部门编码", required = true),
    })
    @GetMapping
    public RestResponse<List<String>> selectByOperCodeAndDeptCode(@RequestParam String operCode, @RequestParam String deptCode) throws Exception {
        return new RestResponse<>(workTerminalCacheService.selectByOperCodeAndDeptCode(operCode, deptCode));
    }

    @ApiOperation(value = "查询接线工作台", notes = "通过话务ID查询出当前的具体缓存信息")
    @GetMapping(value = "/detail")
    public RestResponse<WorkTerminalCache> selectByCallId(@ApiParam(name = "callId", value = "话务ID")@RequestParam String callId) throws Exception {
        return new RestResponse<>(workTerminalCacheService.selectByCallId(callId));
    }
}
